import Vue from 'vue'
import App from './App.vue'
import router from './router/index'
import './plugins/element.js'
import store from './vuex/store'
import './assets/style/iconfont.css' // 矢量图库
import axios from 'axios'
import md5 from 'js-md5'
import htmlToPdf from './util/htmlToPdf'

axios.defaults.withCredentials = true // 解决前端跨域问题

// 全局引入
Vue.use(htmlToPdf)

Vue.prototype.$md5 = md5

Vue.config.productionTip = false

// http response 响应拦截器
axios.interceptors.response.use(
  response => {
    return response
  },
  error => {
    if (error.response) {
      switch (error.response.status) {
        // 返回401，清除token信息并跳转到登录页面
        case 401:
          // sessionStorage.clear()
          break
        case 404:
          router.push({ path: '/noFound' })
          break
        case 500:
          router.push({ path: '/serverError' })
      }
      // 返回接口返回的错误信息
      return Promise.reject(error.response)
    }
  }
)

new Vue({
  router,
  store,
  render: h => h(App),
  data: {
    // 空的实例放到根组件下，所有的子组件都能调用
    Bus: new Vue()
  }
}).$mount('#app')
